<?php
/**
 * Created by PhpStorm.
 * User: DMF
 * Date: 2017/4/7
 * Time: 15:57
 */

namespace Admin\Controller;


class UserController extends \Common\Controller\BaseController
{
    //首页
    public function index(){

        $this->display();
    }
    //管理员
    public function pri(){
        $db = M('user');
        $arr = array(
            'level'=>0,
            'live'=>1,
        );
        $root = $db->where($arr)->select();
        $this->assign('root',$root);
        $this->display();
    }
    //普通用户
    public function pub(){
        $db = M('user');
        $arr = array(
            'level'=>1,
            'live'=>1,
        );
        $consumer = $db->where($arr)->select();
        $this->assign('consumer',$consumer);
        $this->display();
    }
    //用户权限升级
    public function userup(){
        $id = I('id');
        if($id == 0){
            $this->success('当前已经是管理员了，无法再升级',U('pri'));
        }else{
            $db = M('user');
            $result = $db->save(array('id'=>$id,'level'=>0));
            if($result){
                $this->success('你已经升级为管理员了');
            }else{
                $this->error('无法升级为管理员');
            }
        }
    }
    //用户权限降级
    public function userdown(){
        $id = I('id');
        if($id == 1){
            $this->success('你已经是平民了，无法再降级');
        }else{
            $db = M('user');
            $result = $db->save(array('id'=>$id,'level'=>1));
            if($result){
                $this->success('你已经降级为平民了');
            }else{
                $this->error('无法降级为平民');
            }
        }
    }
//    用户删除
    public function del(){
        $id = I('id');
        $result = D('user')->where('id='.$id)->save(array('id'=>$id,'live'=>0));
        if($result){
            $this->success("用户删除成功");
        }else{
            $this->success("用户删除失败");
        }
    }
}